var global_elderId = null;
var global_relationId = null;
$('#vue_vm_list').hide();

elderArrearage_find = function(searchVal) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	
	if(isEmpty(searchVal)) {
		alert('请选择长者');
		return;
	}
	
	openWaiting('正在查找');
	
	find_basic(path+'/elderArrearage/find', searchVal, function(response) {
		closeWaiting();
		
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getTotal:function(todos) {
					var totalPayMoney = 0;
					var payIdStr = '';
					var payIdArray = [];
					
					for(var i=0; i<todos.length; i++) {
						var payMoney = parseFloat(todos[i].arrearageMoney);
						totalPayMoney += payMoney;
						
						var payId = todos[i].elderArrearageId;
						payIdStr += (payIdStr==''? payId: ','+payId);
						payIdArray.push(payId);
					}
					
					return {totalPayMoney:totalPayMoney, payIdArray:payIdArray};
				},
				payCost_save:function(todos) {
					var total = this.getTotal(todos);
					var payWay = parseInt($('input:radio[name="payWay"]:checked').val());
					
					var arrearagePayCostForm = {
						payIdList:total.payIdArray,
						payMoney: total.totalPayMoney,
						payWay: payWay,
						elderId: global_elderId
					}
					
					save_basic(path+'/elderArrearage/payCost', {arrearagePayCostForm:arrearagePayCostForm}, function() {
						alert('补交成功');
						var pageParam = {};
						pageParam.elderId = todos[0].elderId;
						pageParam.elderName = todos[0].elderName;
						pageParam.payType = '欠费补交';
						pageParam.pay = total.totalPayMoney;
						pageParam.staffName = getLoginedUser()? getLoginedUser().staffName: '';
						pageParam.payDate = getStandardNowDay();
						pageParam.paperType = 2;
						pageParam.relationId = global_relationId + '-arrSupple';
                        pageParam.beHospitalId =  todos[0].beHospitalId;
						window.open('0_print_jf.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
					});
				}
			}
		});
		
		if(response.data.length>0) {
			global_elderId = response.data[0].elderId;
			global_relationId = response.data[0].relationId;
		}
		
		$('#vue_vm_list').show();
		$('#totalPayMoney').show();
	});
}